﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace Peer
{

    class Operation
    {
        public Operation(byte operationCode) : this(operationCode, new Dictionary<byte, object>())
        {

        }

        public Operation(byte operationCode, Dictionary<byte, object> parameters)
        {
            OperationCode = operationCode;
            Parameters = parameters;
        }

        public object this[byte parameterKey]
        {
            get { return Parameters[parameterKey]; }
            set { Parameters[parameterKey] = value; }
        }

        public byte OperationCode { get; set; }

        public Dictionary<byte, object> Parameters { get; set; }

        public byte[] Serialize()
        {
            List<object> args = new List<object>
            {
                OperationCode
            };
            foreach (var item in Parameters)
            {
                args.Add(item.Key);
                args.Add(item.Value);
            }
            return MTP.Serialize.MTPSerialize.SerializeArray(args.ToArray());
        }
    }
}
